package com.rg.dao;

import com.rg.model.GoodsType;
import com.rg.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;
//数据访问对象类，用于操作商品类型数据。
//selectAllType方法查询所有商品类型。
public class GoodsTypedao {
    public List<GoodsType> selectAllType() throws SQLException {
        List<GoodsType> TypeList = null;
        try {
            String sql = "SELECT type_id typeId,type_name typeName FROM goods_type";
            QueryRunner queryRunner=new QueryRunner(DruidUtils.getDataSource());
            TypeList = queryRunner.query(sql,new
                    BeanListHandler<GoodsType>(GoodsType.class));
        }catch(SQLException e){
            throw new RuntimeException(e);
        }
        return TypeList;
    }
}
